<template>
  <view class="submitButton flex-items" :class="{positionBottom: position === 'bottom'}" :style="{width: width, backgroundColor: bgColor}">
    <view class="submitBtn" @click="handleExchange" :style="{height: height}">
      <text>{{ text }}</text>
      <image v-if="btnLoadingFlag" :src="`${VUE_APP_STATIC_URL}ui-static/img/loading/loading3.gif`"></image>
    </view>
  </view>
</template>

<script>
import {mapGetters} from 'vuex'

export default {
  name: "submitButton",
  methods: {
    handleExchange() {
      // 将事件传递给父组件
      if (this.btnLoadingFlag) return;
      this.$emit('submitEvent');
    }
  },
  data(){
    return {
      flag:true
    }
  },
  props: {
    text: {
      type: String,
      default: '提交'
    },
    position: {
      type: String,
      default: 'liberty'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '78rpx'
    },
    bgColor: {
      type: String,
      default: 'none'
    }
  },
  computed: {
    ...mapGetters(["btnLoadingFlag"])
  }
}
</script>

<style lang="scss" scoped>
.submitButton {
  .submitBtn {
    width: 690rpx;
    height: 78rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    background: linear-gradient(90deg, #ff9000, #ff5000);
    border-radius: 78rpx;
  }
  image {
    width: 32rpx;
    height: 32rpx;
    margin-left: 10rpx;
  }
}
.positionBottom {
  position: fixed;
  left: 0;
  bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -1rpx 0rpx rgba(197, 202, 207, 0.5);
  background: #ffffff;
  padding: 0 32rpx;
}
</style>
